#include <stdio.h>

//元素elem进栈
int push(int * a, int top, int elem) {
    a[++top] = elem;
    return top;
}

//数据元素出栈
int pop(int * a, int top) {
    if (top == -1)
    {
        /* 判断是否空栈 */
        printf("空栈");
        return -1;
    }
    printf("弹栈元素：%d\n",a[top]);
    top--;
    return top;    
}

int main(int argc, char * argv[]) {
    //定义空数组
    int a[100];
    int top = -1;
    for(int i=1; i<5; i++) {
        top=push(a, top, i);
    }
    for(int j=0; j<5; j++) {
        top=pop(a, top);
    }
    return 0;
}